﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class register : System.Web.UI.Page
{
    public string strcr = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        DataSet ds = new db_aboutUs().selectAboutUs();

        db_blogroll blogroll = new db_blogroll();
        DataSet ds_blogroll = blogroll.selectBlogrollALL();
        blogrollList.DataSource = ds_blogroll.Tables[0].DefaultView;
        blogrollList.DataBind();

        db_copyright cr = new db_copyright();
        DataSet dscr = cr.selectOne();
        strcr = "Copyright &copy; " + dscr.Tables[0].Rows[0]["cryear"].ToString() + " " + dscr.Tables[0].Rows[0]["owner"].ToString() + " ALL Rights Reserved<br/><a href=\"http://www.miibeian.gov.cn\" target=\"_blank\">" + dscr.Tables[0].Rows[0]["approve"].ToString() + "</a>";
    }
    protected void btn_checkName_Click(object sender, EventArgs e)
    {
        if (TXTUsername.Text.Equals(""))
        {
            lbl_check.Text = "请输入用户名";
            TXTUsername.Focus();
        }
        else
        {
            string name = TXTUsername.Text.Trim();
            bool isExist = new db_users().isExistName(name);
            if (isExist)
            {
                lbl_check.Text = "用户名已存在";
            }
            else
            {
                lbl_check.Text = "用户名可以使用";
            }
        }
    }
    protected void cv_username_ServerValidate(object source, ServerValidateEventArgs args)
    {
        string name = TXTUsername.Text.Trim();
        bool isExist = new db_users().isExistName(name);
        if (isExist)
        {
            args.IsValid = false;
            TXTUsername.Focus();
        }
        else
        {
            args.IsValid = true;
        }
    }
    protected void BTNRegister_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            string name = TXTUsername.Text.Trim();
            string pwd = TXTRePwd.Text.Trim();
            string sex = "";
            if (RBTMan.Checked)
            {
                sex = "男";
            }
            else
            {
                sex = "女";
            }
            string email = TXTEmail.Text.Trim();
            db_users users = new db_users();
            if (users.addUser(name, pwd, "100", email, sex, "0"))
            {
                Response.Write("<script language=javascript>alert('用户注册成功！');top.location.href='../stu/login.aspx'</script>");
            }
            else
            {
                Response.Write("<script language=javascript>alert('用户注册失败！');</script>");
            }
        }
    }
}
